<style>
    .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
</style>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
		
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
				<input type="hidden" name="id" value="{{.user_admin.Id}}">
                <label class="layui-form-label required">管理账号</label>
                <div class="layui-input-block">
                    <input type="text" name="username" lay-reqtext="管理账号不能为空" disabled placeholder="请输入管理账号"  value="{{.user_admin.UserName}}" class="layui-input layui-disabled">
                    <tip>管理员账号</tip>
                </div>
            </div>
			<div class="layui-form-item layui-form-text">
                <label class="layui-form-label">头像</label>
                <div class="layui-input-block">
                   <div id="img_upload"> </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label ">昵称</label>
                <div class="layui-input-block">
                    <input type="text" name="nickname"  placeholder="请输入昵称" maxlength="20" value="{{.user_admin.Nickname}}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input type="email" name="email"  placeholder="请输入邮箱" lay-verify="email"  value="{{.user_admin.Email}}" class="layui-input">
                </div>
            </div>
        

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form','miniPage','jquery','CmfUpload'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniPage = layui.miniPage,
			$ = layui.jquery,
			CmfUpload = layui.CmfUpload;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();
		
		/** 上传插件初始化 **/
		var option_init = {
			id:"img_upload", //@params id  上传容器的id 需保证唯一
			type:"once"      //@params type  "once" 单张上传 "more" 多张上传
		}
		//清空之前添加的图片，防止重复渲染历史数据
		CmfUpload.render_data = [];
		//@addUrl 页面首次加载，要初始化渲染的 img url ，可以多次调用addUrl方法渲染多张
		var img_url = "{{.user_admin.Avatar}}"
		CmfUpload.addUrl(img_url);
		//@render 上传插件初始化方法
		CmfUpload.render(option_init);
		
        //监听提交
        form.on('submit(saveBtn)', function (data) {
			var url = "/admin/main/userSetting"
            $.post(url,data.field,function(resp){
				//console.log(resp)
				if(resp.code == 200){
					//修改成功
					layer.msg("保存成功",{end:function(){
						location.reload();
					}});
					
				}else{
					layer.msg(resp.msg);
				}
		    },"json");
            return false;
        });
	
    });
</script>